<div class="Item hr">
    <div class="current">文档管理</div>
    <div class="fr"><a class="btn" href="{:U('Contype/index')}">栏目列表</a></div>
    <div class="fr"><a href="{:U('add', $param)}" class="btn">添加文档</a></div>
</div>
<form autocomplete="off">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">
        <thead>
            <tr height="25" align="center">
                <td width="4%">选择</td>
                <td width="28%" style="text-align:left;">文章标题</td>
                <td width="10%">更新时间</td>
                <td width="10%">类目</td>
                <td width="8%">点击</td>
                <!--<td width="6%">HTML</td>-->
                <td width="8%">发布人</td>
                <td width="10%">操作</td>
            </tr>
        </thead>
        <tbody>
            <volist name="ContentList" id="content" empty="$empty">
            <tr align="center">
                <td>{:genCheckbox('aid', '', $content['id'], false, 'aid')}</td>
                <td style="text-align:left;"><a href="{:U('edit', array('aid' => $content['id']))}">{$content['title']}</a>[ID:{$content['id']}]{$content.flag|IsCommendArchives=###,$attlist}</td>
                <td>{:getDateStr($content['pubdate'])}</td>
                <td>{$content['typename']}</td>
                <td>{$content['click']}</td>
                <!--<td>{$content['ismake']|IsHtmlArchives}</td>-->
                <td>{$content['writer']}</td>
                <td><a href="{:U('edit', array('aid' => $content['id']))}" class="icon icon-black icon-edit" title="编辑"></a> <a href="javascript:;" class="deleted icon icon-black icon-trash " data-url="{:U('delete')}" data-id="{$content.id}" data-title="{$content.title}" title="删除"></a> <a href="{:U('Home/View/index', array('aid' => $content['id']))}" class="icon icon-black icon-web" title="预览" target="_blank"></a></td>
            </tr>
            </volist>
        </tbody>
    </table>
</form>

<div class="page">
    {$page}
</div>
<div class="commonBtnArea" >
<label><input name="" class="chooseAll" type="checkbox"> 全选</label> <label><input name="" class="unsetAll" type="checkbox"> 反选</label>
    <button class="btn" id="deleted" data-url="{:U('delete')}">删除</button>
    
    <select name="setflag" id="setflag" autocomplete="off">
    	<option value="0">选择属性</option>
        <volist name='attlist' id='att'>
            <if condition="$att['att'] neq 'j' && $att['att'] neq 'p'">
                <option value="{$att.att}">{$att.attname}[{$att.att}]</option>
            </if>
        </volist>
    </select>
    <button class="btn setfalg" data-type="add" data-url="{:U('setFlag')}">增加属性</button>
    <button class="btn setfalg" data-type="del" data-url="{:U('setFlag')}">删除属性</button>
</div>

<script type="text/javascript">
$(function(){
	clickCheckbox();
	//单个删除
    $(".deleted").click(function(){
        var url = $(this).data("url");
        var id = $(this).data("id");
        var title = $(this).data("title");

        popup.confirm("您确定删除 <b>" + title + "</b> 文档？", '温馨提示',function(action){
            if(action == 'ok'){
                $.ajax({
					"url" : url,
					"dataType" : "JSON",
					"type" : "POST",
					"data" : {"aid" : id},
					"success" : function(json){
                    if (json.status) {
                        popup.success(json.info, "删除成功", function(){
							if(json.url){
								window.location.href = json.url;
							}else{
								top.window.location.reload();
							}
						});
                    } else {
                        popup.error(json.info);
                        setTimeout(function(){
                            popup.close("asyncbox_error");
                        },2000);
                    }
                }
				});
            }
        });

        return false;
    });
	//批量删除
    $("#deleted").click(function(){
        var url = $(this).data("url");
		var isDeleted = false;
		var aids = [];
		$(".aid").each(function(){
			if($(this).prop("checked")){
				isDeleted = true;
				aids.push($(this).val());
			}
		})
		if(isDeleted){
			popup.confirm("您确定批量删除文档？", '温馨提示',function(action){
				if(action == 'ok'){
					$.ajax({
						"url" : url,
						"dataType" : "JSON",
						"type" : "POST",
						"data" : {"aids" : aids, "act" : "two"},
						"success" : function(json){
						if (json.status) {
							popup.success(json.info, "删除成功", function(){
								if(json.url){
									window.location.href = json.url;
								}else{
									top.window.location.reload();
								}
							});
						} else {
							popup.error(json.info);
							setTimeout(function(){
								popup.close("asyncbox_error");
							},2000);
						}
					}
					});
				}
			});
		}
        return false;
    });
	
	//增加属性
	$(".setfalg").on("click", function(){
        var url = $(this).data("url");
        var type = $(this).data("type");
		var falg = $("#setflag").val();
		var isSet = false;
		var aids = [];
		$(".aid").each(function(){
			if($(this).prop("checked")){
				isSet = true;
				aids.push($(this).val());
			}
		})
		if(isSet){
			if(falg == 0){
				var info = type == 'add' ? '增加' : '删除';
				popup.error("请选择要"+info+"的文档属性！");
				return false;
			}
			popup.confirm("您确定批量操作文档？", '温馨提示',function(action){
				if(action == 'ok'){
					$.ajax({
						"url" : url,
						"dataType" : "JSON",
						"type" : "POST",
						"data" : {"aids" : aids, "type" : type, "falgatt" : falg},
						"success" : function(json){
						if (json.status) {
							popup.success(json.info, "删除成功", function(){
								if(json.url){
									window.location.href = json.url;
								}else{
									top.window.location.reload();
								}
							});
						} else {
							popup.error(json.info);
							setTimeout(function(){
								popup.close("asyncbox_error");
							},2000);
						}
					}
					});
				}
			});
		}else{
			popup.error("请选择要操作的文档！");
		}
        return false;
	});
});
</script>